﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace ORSLibrary
{
    public class Utilities
    {
        public enum MessageType
        {
            info, success, warning, error
        }

        public static void ShowMessage(Literal ctrl, string message, MessageType type)
        {
            ctrl.Text += "<h4 class='alert_" + type.ToString() + "'>" + message + "</h4>";
        }

        public static CustomeDataSourceList BindToEnum(Type enumType, bool isComboBox)
        {
            string[] names = Enum.GetNames(enumType);
            Array values = Enum.GetValues(enumType);
            CustomeDataSourceList ds = new CustomeDataSourceList();
            for (int i = 0; i < names.Length; i++)
            {
                System.Reflection.MemberInfo[] memInfo = enumType.GetMember(names[i]);
                if (memInfo != null && memInfo.Length > 0)
                {
                    object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                    if (attrs != null && attrs.Length > 0)
                    {
                        CustomeDataSource item = new CustomeDataSource();
                        item.ID = (int)values.GetValue(i);
                        item.NameAr = ((DescriptionAttribute)attrs[0]).Description;
                        ds.Add(item);
                    }
                }
            }
            if (isComboBox)
            {
                CustomeDataSource item = new CustomeDataSource();
                item.ID = 0;
                item.NameAr = item.NameEn = "---";

                ds.Insert(0, item);
            }
            return ds;
        }

        public class CustomeDataSource
        {
            public int ID { get; set; }
            public string NameAr { get; set; }
            public string NameEn { get; set; }
        }

        public class CustomeDataSourceList : List<CustomeDataSource> { }
    }
}